<?php
namespace Api\Controller;
use Think\Controller;
class MyController extends CommonController {
    function index(){
        if(IS_POST){
            $info['year']=(I('post.year'))?I('post.year'):(date('Y'));
            $info['month']=(I('post.month'))?I('post.month'):(date('m'));
            //该月的开始时间戳和结束时间戳
            $mydate['beginThismonth']=strtotime($info['year'].'-'. $info['month']);
            $day=date('t',$mydate['beginThismonth']);
            $mydate['endThismonth']=$mydate['beginThismonth']+ 86400*$day  - 1;
            $map['create_time'] = array('between',array($mydate['beginThismonth'].'',$mydate['endThismonth'].''));
            $planlist = M('plan')->where($map)->field('id,create_time')->order('create_time desc')->select();
            $accountlist = M('account')->where($map)->field('id,create_time,money,bigtype')->order('create_time desc')->select();
            $mydata = [];
            $day='';
            foreach ($planlist as $k => $v){
                $day = date('d',$v['create_time']);
                $mydata[$day]['time'] = lbweekday($v['create_time']).' '.date('m月d日',$v['create_time']);
                $mydata[$day]['plannum'] +=1;
            }
            foreach ($accountlist as $k => $v){
                $day = date('d',$v['create_time']);
                if ($v['bigtype'] == 1){//收入
                    $mydata[$day]['in'] += $v['money'];
                }
                else if ($v['bigtype'] == 2){//支出
                    $mydata[$day]['out'] += $v['money'];
                }
            }
            echo lbjson(0,'数据请求成功',$mydata);

        }else
            echo lbjson(1,'请求方式错误',[]);
    }
}